package com.qkjia.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * @author zhaoqiankun
 * @date 2021/12/3
 * 自定义元数据对象
 */
@Component// 组件注入
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Object version = getFieldValByName("version", metaObject);
        if (version == null) {
            // 字段为空，可以进行填充
            setFieldValByName("version",1,metaObject);
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
